#pragma once

#include "GameTime.h"
#include "PhysicsPrereq.h"
#include "Bullet\BulletCollision\CollisionDispatch\btGhostObject.h"
namespace ne{
static void GameTickCallback(btDynamicsWorld* world, btScalar timeStep);

class IComponentCollision;
class GameObjectManager;
class PhysicsWorld{
public:
	PhysicsWorld(void);
	~PhysicsWorld(void);
	void Init();	// allocates memory for the required components in order for Bullet Physics to function properly. This should be called once only during startup.
	void Shut();	// deletes all memory allocated for Bullet Physics Engine. Rigidbodies, Constraints etc are not removed during this process so they need to be removed manually.
	void SetGravity(float x, float y, float z);		// change the gravity setting
	void SetGravity(const btVector3& gravity);
	void SetGravity(const Ogre::Vector3& gravity);
	void SetDrawDebugData(bool value){m_drawDebugData=value;}
	bool GetDrawDebugData()const{return m_drawDebugData;}

	btDiscreteDynamicsWorld* GetDynamicWorld() const {return m_dynamicWorld;}
	
	void Step(GameTime& gameTime);
	void ProcessObjectSimulationAndCollision(btScalar timeStep);
	void InitDebugDraw(Ogre::SceneManager* sceneManager);
	void SetGameObjectManager(GameObjectManager* gameObjectManager){m_gameObjectManager=gameObjectManager;}
	void Close();
	void RemoveContact(IComponentCollision* componentCollision);
	
private:
	GameObjectManager*						m_gameObjectManager;
	bool									m_drawDebugData;
	typedef std::vector<std::pair<const btCollisionObject*,const btCollisionObject*>> CollisionList;
	CollisionList							m_contacts;
	btBroadphaseInterface*					m_broadphaseInterface;
	btDefaultCollisionConfiguration*		m_collisionConfiguration;
	btCollisionDispatcher*					m_collisionDispatcher;
	btSequentialImpulseConstraintSolver*	m_sequentialImpulseConstraintSolver;
	btDiscreteDynamicsWorld*				m_dynamicWorld;
	btIDebugDraw*							m_debugDraw;
	btGhostPairCallback*					m_ghostPairCallback;
	btVector3								m_gravity;		// the gravity of the dynamic world, this value is set to -9.8 (on Y) by default.
};
}